home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / DISHOW.C < prev    next >
C/C++ Source or Header  |  1993-06-25  |  9KB  |  301 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    dishow.c
  5. //   Title:    Data File I/O Library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains code to display the contents of data files.
  25. //
  26. //    The code in this module should be written entirely in C. 
  27. //    Do not use any C++ constructs.
  28. //
  29. //    This module is portable to:
  30. //        DOS 3.X+
  31. //        MS Windows 3.X+
  32. //        OS/2 2.X+
  33. //        OS/2 2.0 PM
  34. //        SCO UNIX.
  35. //
  36. //    The following compilers are supported:
  37. //        MSC 6.0A
  38. //        MSC/C++ 7.0
  39. //        Borland C++ 3.1 for DOS
  40. //        Borland C++ 1.0 for OS/2 2.X
  41. //        SCO UNIX cc
  42. //
  43. //----------------------------------------------------------------------------
  44. #include <di.h>
  45.  
  46. //----------------------------------------------------------------------------
  47. //    Mapping of file types
  48. //----------------------------------------------------------------------------
  49. DIOTYPE adiotype[] =
  50.     {
  51.     { DFT_RANDOM,     "RAND", "Random Access Data" },
  52.     { DFT_DELETED,       "DEL ", "Deleted file" },
  53.     { DFT_BLOCK,       "BLCK", "Blocked Data" },
  54.     { DFT_ISAM_DATA,  "ISAM", "ISAM Data" },
  55.     { DFT_ISAM0,       "ISM0", "ISAM Index Level 0" },
  56.     { DFT_ISAM1,       "ISM1", "ISAM Index Level 1" },
  57.     { DFT_ISAM2,       "ISM2", "ISAM Index Level 2" },
  58.     { DFT_ISAM3,       "ISM3", "ISAM Index Level 3" },
  59.     { DFT_ISAM4,       "ISM4", "ISAM Index Level 4" },
  60.     { DFT_ISAM5,       "ISM5", "ISAM Index Level 5" },
  61.     { DFT_ISAM6,       "ISM6", "ISAM Index Level 6" },
  62.     { DFT_ISAM7,       "ISM7", "ISAM Index Level 7" },
  63.     { DFT_ISAM8,       "ISM8", "ISAM Index Level 8" },
  64.     { DFT_ISAM9,       "ISM9", "ISAM Index Level 9" },
  65.     { DFT_ISAMA,       "ISMA", "ISAM Index Level A" },
  66.     { DFT_ISAMB,       "ISMB", "ISAM Index Level B" },
  67.     { DFT_ISAMC,       "ISMC", "ISAM Index Level C" },
  68.     { DFT_ISAMD,       "ISMD", "ISAM Index Level D" },
  69.     { DFT_ISAME,       "ISME", "ISAM Index Level E" },
  70.     { DFT_ISAMF,       "ISMF", "ISAM Index Level F" },
  71.     { DFT_ISAMF,       "ISMF", "ISAM Index Level F" },
  72.     { DFT_ISAM_RECNO,    "IREC", "ISAM Record # Index" },
  73.     { 0, NULL, NULL }
  74.     };
  75.  
  76.  
  77. //----------------------------------------------------------------------------
  78. //    Prototypes
  79. //----------------------------------------------------------------------------
  80. static BOOL FN_L DioShowDirLong(PDATADIR, SIZET);
  81. static BOOL FN_L DioShowDirShort(PDATADIR, SIZET);
  82. static BOOL FN_L DioShowHeader(PDATAHDR);
  83.  
  84.  
  85. //----------------------------------------------------------------------------
  86. //   Description:    Show all directory entries in file.
  87. //    Parameters:    pcsz        File name.
  88. //                        fLong        If true, show in long format. Otherwise display
  89. //                                    in short format.
  90. //       Returns:    TRUE if successful.
  91. //----------------------------------------------------------------------------
  92. BOOL FN_E DioShow(PCSZ pcsz, BOOL fLong)
  93. {
  94.     CHAR szName[DFH_NAME+1];
  95.     HPF hpf;
  96.     DATAHDR hdr;
  97.     DATADIR dir;
  98.     LONG lTotal = 0;
  99.     SIZET cDir;
  100.     BOOL fResult = FALSE;
  101.     BOOL fUser;
  102.  
  103.     Output("File '%s':\n", pcsz);
  104.     if (HIUSHORT(pcsz))
  105.         {
  106.         if (!DioOpenPhysical(pcsz, &hpf, FALSE))
  107.             return FALSE;
  108.         fUser = FALSE;
  109.         }
  110.     else
  111.         {
  112.         hpf = LOUSHORT(pcsz);
  113.         Assert(hpf >= 0 && hpf < MAX_PHYSICAL_FILES);
  114.         Assert(di.physical[hpf].fUsed);
  115.         fUser = TRUE;
  116.         }
  117.     if (!DioHeaderRead(hpf, &hdr))
  118.         goto ERROR_EXIT;
  119.     if (fLong)
  120.         {
  121.         if (!DioShowHeader(&hdr))
  122.             goto ERROR_EXIT;
  123.         }
  124.     else
  125.         {
  126.         memcpy(szName,0,sizeof(szName));
  127.         memcpy(szName,hdr.chName,sizeof(hdr.chName));
  128.         Output("\n%s\n\n", szName);
  129.         Output("   #   Name                              Type     Flags      Base    Length\n");
  130.         Output("  -------------------------------------------------------------------------\n");
  131.         }
  132.  
  133.     for (cDir = 0; cDir < (SIZET)hdr.usDirectoryEntries; ++cDir)
  134.         {
  135.         if (!DioDirRead(hpf, cDir, &dir))
  136.             goto ERROR_EXIT;
  137.         if (dir.chName[0])
  138.             lTotal += (LONG)dir.flen;
  139.         if (fLong)
  140.             {
  141.             if (!DioShowDirLong(&dir, cDir))
  142.                 goto ERROR_EXIT;
  143.             }
  144.         else
  145.             {
  146.             if (!DioShowDirShort(&dir, cDir))
  147.                 goto ERROR_EXIT;
  148.             }
  149.         while (KbdReady())
  150.            if (KbdChar() == '\x1B')
  151.                 {
  152.                 Output("\nAborted!\n");
  153.                 goto ERROR_EXIT;
  154.                 }                                
  155.         }
  156.     Output("%u/%u entries. %ld bytes.\n\n",
  157.         hdr.usDirectoryUsed, hdr.usDirectoryEntries, lTotal);
  158.  
  159.     fResult = TRUE;
  160.  
  161. ERROR_EXIT:
  162.     if (!fUser)
  163.         DioClosePhysical(hpf);
  164.     return fResult;
  165. }
  166.  
  167.  
  168. //----------------------------------------------------------------------------
  169. //   Description:    Show file directory entry in long format
  170. //    Parameters:    pdir        Directory data.
  171. //                        cDir        Directory offset
  172. //       Returns:    TRUE if successful.
  173. //----------------------------------------------------------------------------
  174. static BOOL FN_L DioShowDirLong(PDATADIR pdir, SIZET cDir)
  175. {
  176.     CHAR szName[DFD_NAME+1];
  177.     PSZ pszType = "Unknown File Type";
  178.     SIZET i;
  179.  
  180.     for (i = 0; adiotype[i].pszShort; ++i)
  181.         if (adiotype[i].usType == pdir->usType)
  182.             {
  183.             pszType = adiotype[i].pszLong;
  184.             break;
  185.             }
  186.     Output("*** Directory %u ***\n", cDir);
  187.     memcpy(szName,0,sizeof(szName));
  188.     memcpy(szName,pdir->chName,sizeof(pdir->chName));
  189.     Output("           Name: %s\n", szName);
  190.     Output("           Type: %s\n", pszType);
  191.     Output("     Block size: %u\n", pdir->usBlockSize);
  192.     Output("           Base: %ld\n", pdir->fbase);
  193.     Output("         Length: %ld\n", pdir->flen);
  194.     Output("          Flags: 0x%08lX\n", pdir->fl);
  195.     Output("            CRC: 0x%08lX\n", pdir->crc);
  196.     Output("       Data CRC: 0x%08lX\n", pdir->crcData);
  197.     Output("   User Version: %04X\n", pdir->usUserVersion);
  198.     Output("      User data: ");
  199.     for (i = 0; i < sizeof(pdir->bUser); ++i)
  200.         {
  201.         Output("%02X ", pdir->bUser[i]);
  202.         if (((i+1) % 16) == 0)
  203.             Output("\n                 ");
  204.         }
  205.     Output("\n");
  206.     return TRUE;
  207. }
  208.  
  209.  
  210. //----------------------------------------------------------------------------
  211. //   Description:    Show all directory entries in file in abbreviate mode.
  212. //    Parameters:    pdir        Directory data.
  213. //                        cDir        Directory offset
  214. //       Returns:    TRUE if successful.
  215. //----------------------------------------------------------------------------
  216. static BOOL FN_L DioShowDirShort(PDATADIR pdir, SIZET cDir)
  217. {
  218.     CHAR szName[DFD_NAME+1];                    
  219.  
  220.     Output("  %03d: ", cDir);
  221.     if (pdir->chName[0])
  222.         {
  223.         PSZ pszType = "????";
  224.         SIZET i;
  225.  
  226.         for (i = 0; adiotype[i].pszShort; ++i)
  227.             if (adiotype[i].usType == pdir->usType)
  228.                 {
  229.                 pszType = adiotype[i].pszShort;
  230.                 break;
  231.                 }
  232.         if (pdir->usType == DFT_DELETED)
  233.             strcpy(szName, "*** DELETED! ***");
  234.         else
  235.             {
  236.             memcpy(szName,0,sizeof(szName));
  237.             memcpy(szName, pdir->chName,sizeof(pdir->chName));
  238.             }
  239.         Output("%-*s  %4s  %08lX  %8ld  %8ld\n",
  240.             sizeof(pdir->chName), szName,
  241.             pszType, pdir->fl, pdir->fbase, pdir->flen);
  242.         }
  243.     else
  244.         Output("*** NOT USED ***\n");
  245.  
  246.     return TRUE;
  247. }
  248.  
  249.  
  250. //----------------------------------------------------------------------------
  251. //   Description:    Show file header data
  252. //    Parameters:    phdr        Header data to display.
  253. //       Returns:    TRUE if successful.
  254. //----------------------------------------------------------------------------
  255. static BOOL FN_L DioShowHeader(PDATAHDR phdr)
  256. {
  257.     CHAR szName[DFH_NAME+1];                    
  258.     struct tm *tm;
  259.     SIZET i;
  260.     CHAR szAppId[DFH_APP_ID+1];
  261.  
  262.     Output("*** Header ***\n");
  263.     memcpy(szName,0,sizeof(szName));
  264.     memcpy(szName,phdr->chName,sizeof(phdr->chName));
  265.     Output("           Name: %s\n", szName);
  266.     Output("             ID: 0x%08lX\n", phdr->lId);
  267.     Output("        Version: %u.%02u\n", (phdr->usVersion >> 8), (phdr->usVersion & 0x00FF));
  268.     Output("    Directories: %u of %u directories used.\n",phdr->usDirectoryUsed, phdr->usDirectoryEntries);
  269.     Output("          Flags: 0x%08lX\n", phdr->fl);
  270.  
  271.     tm = localtime((time_t *)&phdr->timetCreated);
  272.     Output("        Created: %2d:%02d:%02d %2d/%02d/%4d.\n",
  273.         tm->tm_hour, tm->tm_min, tm->tm_sec,
  274.         tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
  275.  
  276.     tm = localtime((time_t *)&phdr->timetModified);
  277.     Output("  Last Modified: %2d:%02d:%02d %2d/%02d/%4d.\n",
  278.         tm->tm_hour, tm->tm_min, tm->tm_sec,
  279.         tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
  280.  
  281.     Output("            CRC: 0x%08lX\n", phdr->crc);
  282.     Output("   User Version: %04X\n", phdr->usUserVersion);
  283.  
  284.     memcpy(szAppId, phdr->szAppId, 4);
  285.     szAppId[4] = '\0';
  286.     Output(" Application ID: %s\n", szAppId);
  287.  
  288.     Output("      User data: ");
  289.     for (i = 0; i < sizeof(phdr->bUser); ++i)
  290.         {
  291.         Output("%02X ", phdr->bUser[i]);
  292.         if (((i+1) % 16) == 0)
  293.             Output("\n" "                 ");
  294.         }
  295.     Output("\n");
  296.     return TRUE;
  297. }
  298. //----------------------------------------------------------------------------
  299. //------------------------------- End of File --------------------------------
  300. //----------------------------------------------------------------------------
  301.